package com.example.everying.controller.content;/*
 * 项目名称: everything
 * 文件名: PublishTemplateController
 * 作者: 张泽阳
 * 日期: 2025/8/8
 * 描述:
 */

import com.example.everying.model.dto.content.PublishTemplatePageDto;
import com.example.everying.model.entity.content.PublishTemplate;
import com.example.everying.service.content.PublishTemplateService;
import com.example.everying.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/publishTemplate")
@Api(tags = "发布模板")
@Slf4j
public class PublishTemplateController {

    @Autowired
    private PublishTemplateService publishTemplateService;

    @ApiOperation("添加模板")
    @PostMapping("/addTemplate")
    public Result<?> addTemplate(@RequestBody PublishTemplate publishTemplate){
        return publishTemplateService.addTemplate(publishTemplate);
    }

    @ApiOperation("编辑模板")
    @PostMapping("/editTemplate")
    public Result<?> editTemplate(@RequestBody PublishTemplate publishTemplate){
        return publishTemplateService.updateTemplate(publishTemplate);
    }

    @ApiOperation("删除模板")
    @PostMapping("/deleteTemplate")
    public Result<?> deleteTemplate(@RequestBody PublishTemplate publishTemplate){
        return publishTemplateService.deleteTemplateById(publishTemplate.getId());
    }

    @ApiOperation("模板列表")
    @PostMapping("/list")
    public Result<?> list(){
        return publishTemplateService.templateList();
    }

    @ApiOperation("根据模板类型返回模板列表")
    @PostMapping("/listByPublishType")
    public Result<?> listByPublishType(@RequestBody PublishTemplate publishTemplate){
        return publishTemplateService.templateListByPublishType(publishTemplate);
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result<?> page(@RequestBody PublishTemplatePageDto publishTemplatePageDto){
        return publishTemplateService.selectPage(publishTemplatePageDto);
    }

    @ApiOperation("使用模版")
    @PostMapping("/useTemplate")
    public Result<?> useTemplate(@RequestBody PublishTemplate publishTemplate){
        return publishTemplateService.useTemplate(publishTemplate);
    }
}
